/**
 * @mbggenerated
 * @author wujian
 */
package bearworker.zxl.dao.mapper;

import bearworker.zxl.entity.DeliveryOrder;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface DeliveryOrderMapper {
    /* @mbggenerated */
    @Delete({
        "delete from delivery_order",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /* @mbggenerated */
    @Insert({
        "insert into delivery_order (order_no, sender_id, ",
        "original_price, pay_price, ",
        "discount_price, discount_way_id, ",
        "wechat_pay_no, state, ",
        "create_time)",
        "values (#{orderNo,jdbcType=VARCHAR}, #{senderId,jdbcType=INTEGER}, ",
        "#{originalPrice,jdbcType=INTEGER}, #{payPrice,jdbcType=INTEGER}, ",
        "#{discountPrice,jdbcType=INTEGER}, #{discountWayId,jdbcType=INTEGER}, ",
        "#{wechatPayNo,jdbcType=VARCHAR}, #{state,jdbcType=TINYINT}, ",
        "#{createTime,jdbcType=TIMESTAMP})"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(DeliveryOrder record);

    /* @mbggenerated */
    @InsertProvider(type=DeliveryOrderSqlProvider.class, method="insertSelective")
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insertSelective(DeliveryOrder record);

    /* @mbggenerated */
    @Select({
        "select",
        "id, order_no, sender_id, original_price, pay_price, discount_price, discount_way_id, ",
        "wechat_pay_no, state, create_time",
        "from delivery_order",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="sender_id", property="senderId", jdbcType=JdbcType.INTEGER),
        @Result(column="original_price", property="originalPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="discount_way_id", property="discountWayId", jdbcType=JdbcType.INTEGER),
        @Result(column="wechat_pay_no", property="wechatPayNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    DeliveryOrder selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, order_no, sender_id, original_price, pay_price, discount_price, discount_way_id, ",
            "wechat_pay_no, state, create_time",
            "from delivery_order",
            "where order_no = #{0,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="sender_id", property="senderId", jdbcType=JdbcType.INTEGER),
            @Result(column="original_price", property="originalPrice", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.INTEGER),
            @Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.INTEGER),
            @Result(column="discount_way_id", property="discountWayId", jdbcType=JdbcType.INTEGER),
            @Result(column="wechat_pay_no", property="wechatPayNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    DeliveryOrder selectByOrderNo(String orderNo);

    /* @mbggenerated */
    @UpdateProvider(type=DeliveryOrderSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(DeliveryOrder record);

    /* @mbggenerated */
    @Update({
        "update delivery_order",
        "set order_no = #{orderNo,jdbcType=VARCHAR},",
          "sender_id = #{senderId,jdbcType=INTEGER},",
          "original_price = #{originalPrice,jdbcType=INTEGER},",
          "pay_price = #{payPrice,jdbcType=INTEGER},",
          "discount_price = #{discountPrice,jdbcType=INTEGER},",
          "discount_way_id = #{discountWayId,jdbcType=INTEGER},",
          "wechat_pay_no = #{wechatPayNo,jdbcType=VARCHAR},",
          "state = #{state,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(DeliveryOrder record);
    
    @Select({
        "select",
        "a.id, a.order_no, a.sender_id, a.original_price, a.pay_price, a.discount_price, a.discount_way_id, ",
        "a.wechat_pay_no, a.state, a.create_time,DATE_FORMAT(a.create_time,'%Y-%m-%d %H:%i:%s') as showTime",
        "from delivery_order a,delivery_sender b where a.sender_id = b.id and b.user_id = #{userId,jdbcType=INTEGER} order by a.create_time desc"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="sender_id", property="senderId", jdbcType=JdbcType.INTEGER),
        @Result(column="original_price", property="originalPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="discount_way_id", property="discountWayId", jdbcType=JdbcType.INTEGER),
        @Result(column="wechat_pay_no", property="wechatPayNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="showTime", property="showTime", jdbcType=JdbcType.VARCHAR)
    })
    List<DeliveryOrder> selectByUserId(@Param("userId")Integer userId);
    
    @Select({
        "select",
        "id, order_no, sender_id, original_price, pay_price, discount_price, discount_way_id, ",
        "wechat_pay_no, state, create_time",
        "from delivery_order",
        "where sender_id = #{userId,jdbcType=INTEGER} AND state = #{state,jdbcType=TINYINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="sender_id", property="senderId", jdbcType=JdbcType.INTEGER),
        @Result(column="original_price", property="originalPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.INTEGER),
        @Result(column="discount_way_id", property="discountWayId", jdbcType=JdbcType.INTEGER),
        @Result(column="wechat_pay_no", property="wechatPayNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<DeliveryOrder> selectByUserIdAndState(@Param("userId")Integer userId,@Param("state")Integer state);

    @Select({
            "select",
            "id, order_no, sender_id, original_price, pay_price, discount_price, discount_way_id, ",
            "wechat_pay_no, state, create_time",
            "from delivery_order",
            "where id = #{id,jdbcType=INTEGER} AND state = #{state,jdbcType=TINYINT}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="sender_id", property="senderId", jdbcType=JdbcType.INTEGER),
            @Result(column="original_price", property="originalPrice", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.INTEGER),
            @Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.INTEGER),
            @Result(column="discount_way_id", property="discountWayId", jdbcType=JdbcType.INTEGER),
            @Result(column="wechat_pay_no", property="wechatPayNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    DeliveryOrder selectByPrimaryKeyandState(@Param("id")Integer id,@Param("state")Integer state);
}

